<template>
  <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose title="文件生成详情为：" width="900px">
    <div class="sync-padding">
      <div class="base-desc">
        <ul style='list-style-type: disc;margin-left: 20px;'>
          <li v-for="(item, index) in fileList">
            {{ item }}
            <a-tooltip title='entity实体，点击跳转对应预览！' v-if="index == entityIdx">
              <a-icon @click='handleEntityClick(item)' type="question-circle" class="sync-text" />
            </a-tooltip>
          </li>
        </ul>
      </div>
    </div>
    <template #footer>
      <a-button @click="closeModal">关闭</a-button>
      <a-button @click="handleViewFileTree" type="primary">预览</a-button>
    </template>
    <GenViewFileTreeModal @register="registerGenViewFileTreeModal" @success="handleGenViewFileTreeSuccess" />
  </BasicModal>
</template>

<script lang="ts" setup>
import { ref, computed, unref } from 'vue';
import { useModal } from '/@/components/Modal';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { genBaseFormSchema } from '../genData';
import { getCode, getTableInfo } from '../genApi';
import { VALUE_SPLIT } from 'ant-design-vue/es/vc-cascader/utils/commonUtil';
import GenViewFileTreeModal from './genViewFileTreeModal.vue'
import { useMessage } from '/@/hooks/web/useMessage'; // 轻提醒
const { createMessage: $message } = useMessage(); // 解构
// Emits声明
const emit = defineEmits(['register', 'success']);
const entityIdx = ref();
const fileList = ref([]);
const tableId = ref([]);

const [registerGenViewFileTreeModal, { openModal: openGenViewFileTreeModal }] = useModal();

//弹出框初始化
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {

  console.log('文件预览列表111111111111', data);
  //重置表单
  let getFileList = data?.fileList;

  getFileList.forEach((item, index) => {
    if (item.includes('entity')) {
      entityIdx.value = index;
    }
  });
  console.log('entity下标：', entityIdx.value);
  fileList.value = getFileList;
  tableId.value = data?.tableId;
});

/**
 * 实体类点击事件
 */
function handleEntityClick(item) {
  $message.info('实体类跳转中....' + item);
}

/**
 * 成功回调-预览文件树关闭
 */
function handleGenViewFileTreeSuccess(params) {
  $message.info('预览文件树关闭....' + params);
}

//预览事件
async function handleViewFileTree() {
  //将list组装成树结构
  let params = {
    tableId: tableId.value,
  }
  openGenViewFileTreeModal(true, params);
}
</script>

<style lang="less" scoped>
/** 时间和数字输入框样式 */
:deep(.ant-input-number) {
  width: 100%;
}

:deep(.ant-calendar-picker) {
  width: 100%;
}
</style>